package com.power.sifa.correction.dao;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.Repository;
import org.springframework.data.repository.query.Param;
import com.power.sifa.correction.model.Cre_work_record;

import javax.transaction.Transactional;
import java.io.Serializable;
import java.util.List;

/**
 * 处置记录 持久层(hibernate)
 */

public interface Cre_work_recordDao extends JpaRepository<Cre_work_record, Serializable>, JpaSpecificationExecutor<Cre_work_record>, Repository<Cre_work_record, Serializable>, Cre_work_recordDaoCustom<Cre_work_record, Serializable> {

   @Modifying
   @Transactional
   @Query("delete  from Cre_work_record s where  s.id in (:ids) ")
   void removeByIds(@Param("ids") List<Integer> ids);

   /**
    * 根据预警id查询处置记录
    * @param warnid
    * @return
    */
   @Query(value = "select a.* from cre_work_record a left join cre_work b on a.workid = b.id left join cre_warning c on b.warnid = c.id where c.id is not null and c.id = :warnid order by exectime desc", nativeQuery = true)
   List<Cre_work_record> findListByWarnId(String warnid);
}
